import request from '../utils/request';

/**
 * 用户登录
 */
export const userLogin = (params) => {
    return request({
        url: '/security/oauth/token',
        method: 'post',
        params: params
    });
};

/**
 * 获取用户相关信息
 */
export const userInfo = () => {
    return request({
        url: '/user/loginInfo',
        method: 'get'
    });
};

/**
 * 获取登录用户menus
 */
export const userMenus = () => {
    return JSON.parse(localStorage.getItem('Permission'));
};

/**
 * 获取所有menus
 */
export const menus = () => {
    return request({
        url: '/user/menus',
        method: 'get'
    });
};

export const saveMenu = (data) => {
    return request({
        url: '/user/menus/save',
        method: 'post',
        data : data
    });
};

export const delMenu = (data) => {
    return request({
        url: '/user/menus/del',
        method: 'post',
        data : data
    });
};
/**
 * 菜单 end
 */

/**
 * 用户列表
 */
export const userList = (data) => {
    return request({
        url: '/user/list',
        method: 'post',
        data: data
    });
};

/**
 * 编辑用户信息
 */
export const saveUser = (data) => {
    return request({
        url: '/user/save',
        method: 'post',
        data: data
    });
};

/**
 * 权限列表
 */
export const roleList = (data) => {
    return request({
        url: '/user/role/list',
        method: 'post',
        data: data
    });
};

/**
 * 保存权限
 */
export const saveRole = (data) => {
    return request({
        url: '/user/role/save',
        method: 'post',
        data: data
    });
};

/**
 * 保存角色权限
 * @param data
 */
export const saveRoleMenus = (data) => {
    return request({
        url: '/user/role/menus/save',
        method: 'post',
        data: data
    });
};


export const fetchData = () => {
    return request({
        url: './mock/table.json',
        method: 'get'
    });
};

export const fetchUserData = () => {
    return {
        "list": [
            {
                "id": 1,
                "name": "张三",
                "password": "123",
                "email": "123@qq.com",
                "phone": "12345678944",
                "date": "2024-01-01",
                "role": "管理员"
            },
            {
                "id": 2,
                "name": "李四",
                "password": "123",
                "email": "1234@qq.com",
                "phone": "12345678945",
                "date": "2024-01-01",
                "role": "普通用户"
            }
        ],
        "pageTotal": 2
    };
};

